// drama_vip_ads.js

let body = $response.body;
let obj = JSON.parse(body);

// 顶层 sortedItems
if (obj?.data?.sortedItems) {
  obj.data.sortedItems.forEach(item => {
    item.canShowVip = false;
    item.canPlay = true;
    item.initialQuality = false;
  });

  const aiItem = obj.data.sortedItems.find(item => item.qualityDescription === "AI原画");
  if (aiItem) aiItem.initialQuality = true;
}

// watchInfo.sortedItems
if (obj?.data?.watchInfo?.sortedItems) {
  obj.data.watchInfo.sortedItems.forEach(item => {
    item.canShowVip = false;
    item.canPlay = true;
    item.initialQuality = false;
  });

  const aiItem2 = obj.data.watchInfo.sortedItems.find(item => item.qualityDescription === "AI原画");
  if (aiItem2) aiItem2.initialQuality = true;
}

// watchInfo 设置
if (obj?.data?.watchInfo) {
  obj.data.watchInfo.externalAds = false;
  obj.data.watchInfo.currentQuality = "AI_OD";
}

// ✅ 关键补充：修改 m3u8.currentQuality
if (obj?.data?.watchInfo?.m3u8) {
  obj.data.watchInfo.m3u8.externalAds = false;
  obj.data.watchInfo.m3u8.currentQuality = "AI_OD";
}

$done({ body: JSON.stringify(obj) });
